package edu.stu.recyclerviewscrollbar.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import edu.stu.recyclerviewscrollbar.databinding.ItemImgInfoBinding
import edu.stu.recyclerviewscrollbar.entity.ImageInfo

class ImgAdapter(
    val context: Context,
    val data: List<ImageInfo>
) : RecyclerView.Adapter<BindingViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = BindingViewHolder(
        ItemImgInfoBinding.inflate(
            LayoutInflater.from(context),
            parent,
            false
        )
    )

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: BindingViewHolder, position: Int) {
        val item = data[position]
        val binding = holder.binding as ItemImgInfoBinding
        binding.apply {
            textView.text = item.name
            imageView.setImageResource(item.src)
        }
    }
}